package kr.hkit.androidcomplete02.ch16;

import java.util.Calendar;

import kr.hyunist.androidcomplete01.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class ShowDialogEx extends Activity {
	final static int SAMPLE_DLG = 0;
	final static int QUESTION_DLG = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_showdialog);
	}

	@SuppressWarnings("deprecation")
	public void mOnClick(View v) {
		switch (v.getId()) {
		case R.id.ch16_sd_call1:
			showDialog(SAMPLE_DLG);
			break;
		case R.id.ch16_sd_call2:
			showDialog(QUESTION_DLG);
			break;
		}
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		Log.d("ShowDialogEx", "onCreateDialog");
		switch (id) {
		case SAMPLE_DLG:
			return new AlertDialog.Builder(this).setTitle("notice")
					.setMessage("opened dialog")
					.setIcon(R.drawable.ic_launcher)
					.setPositiveButton("Closing Dialog", null).create();
		case QUESTION_DLG:
			return new AlertDialog.Builder(this).setTitle("Question")
					.setMessage("아침은 쳐 드셨나요?").setPositiveButton("Eating", null)
					.setNegativeButton("Noting Eat", null).create();
		}
		return null;

	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		switch(id){
		case SAMPLE_DLG:
			break;
		case QUESTION_DLG:
			Calendar cal = Calendar.getInstance();
			String stime = String.format("%d : %d :%d", cal.get(Calendar.HOUR_OF_DAY),
					cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)
					);
			dialog.setTitle(stime);
			break;
		}
	}
	
	
}
